{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2021-03-29 08:22:18] Try to use the default NATS-Bench (topology) path from fast_mode=True and path=None.\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "import numpy as np\n",
    "from nats_bench import create\n",
    "from pprint import pprint\n",
    "# Create the API for tologoy search space\n",
    "api = create(None, 'tss', fast_mode=True, verbose=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The architecture-index for the largest model is 1462\n",
      "Its performance on cifar10 with 12-epoch-training\n",
      "{'comment': 'In this dict, train-loss/accuracy/time is the metric on the '\n",
      "            'train+valid sets of CIFAR-10. The test-loss/accuracy/time is the '\n",
      "            'performance of the CIFAR-10 test set after training on the '\n",
      "            'train+valid sets by 12 epochs. The per-time and total-time '\n",
      "            'indicate the per epoch and total time costs, respectively.',\n",
      " 'test-accuracy': 82.2,\n",
      " 'test-all-time': 25.68491765430996,\n",
      " 'test-loss': 0.5235109260559082,\n",
      " 'test-per-time': 2.14040980452583,\n",
      " 'train-accuracy': 83.78,\n",
      " 'train-all-time': 415.2997846603394,\n",
      " 'train-loss': 0.4719834935951233,\n",
      " 'train-per-time': 34.60831538836162}\n",
      "Its performance on cifar10 with 200-epoch-training\n",
      "{'comment': 'In this dict, train-loss/accuracy/time is the metric on the '\n",
      "            'train+valid sets of CIFAR-10. The test-loss/accuracy/time is the '\n",
      "            'performance of the CIFAR-10 test set after training on the '\n",
      "            'train+valid sets by 200 epochs. The per-time and total-time '\n",
      "            'indicate the per epoch and total time costs, respectively.',\n",
      " 'test-accuracy': 93.76,\n",
      " 'test-all-time': 428.08196090516384,\n",
      " 'test-loss': 0.29643801399866737,\n",
      " 'test-per-time': 2.1404098045258193,\n",
      " 'train-accuracy': 99.968,\n",
      " 'train-all-time': 6921.6630776723405,\n",
      " 'train-loss': 0.0021994023492435616,\n",
      " 'train-per-time': 34.6083153883617}\n",
      "Its performance on cifar100 with 12-epoch-training\n",
      "{'test-accuracy': 44.97999995727539,\n",
      " 'test-all-time': 12.84245882715498,\n",
      " 'test-loss': 2.069740362548828,\n",
      " 'test-per-time': 1.070204902262915,\n",
      " 'train-accuracy': 46.014,\n",
      " 'train-all-time': 415.2997846603394,\n",
      " 'train-loss': 1.9952968555450439,\n",
      " 'train-per-time': 34.60831538836162,\n",
      " 'valid-accuracy': 44.05999992675781,\n",
      " 'valid-all-time': 12.84245882715498,\n",
      " 'valid-loss': 2.077388186645508,\n",
      " 'valid-per-time': 1.070204902262915,\n",
      " 'valtest-accuracy': 44.52,\n",
      " 'valtest-all-time': 25.68491765430996,\n",
      " 'valtest-loss': 2.073564303588867,\n",
      " 'valtest-per-time': 2.14040980452583}\n",
      "Its performance on cifar100 with 200-epoch-training\n",
      "{'test-accuracy': 71.10666660563152,\n",
      " 'test-all-time': 214.04098045258192,\n",
      " 'test-loss': 1.3540414614995322,\n",
      " 'test-per-time': 1.0702049022629097,\n",
      " 'train-accuracy': 99.79133333333334,\n",
      " 'train-all-time': 6921.6630776723405,\n",
      " 'train-loss': 0.02413411712328593,\n",
      " 'train-per-time': 34.6083153883617,\n",
      " 'valid-accuracy': 70.70666666259766,\n",
      " 'valid-all-time': 214.04098045258192,\n",
      " 'valid-loss': 1.3654081104278564,\n",
      " 'valid-per-time': 1.0702049022629097,\n",
      " 'valtest-accuracy': 70.90666666666667,\n",
      " 'valtest-all-time': 428.08196090516384,\n",
      " 'valtest-loss': 1.3597248032251994,\n",
      " 'valtest-per-time': 2.1404098045258193}\n",
      "Its performance on ImageNet16-120 with 12-epoch-training\n",
      "{'test-accuracy': 22.39999992879232,\n",
      " 'test-all-time': 7.7054752962929856,\n",
      " 'test-loss': 3.1626377182006835,\n",
      " 'test-per-time': 0.6421229413577488,\n",
      " 'train-accuracy': 21.68885959195242,\n",
      " 'train-all-time': 1260.0195466594694,\n",
      " 'train-loss': 3.1863493608815463,\n",
      " 'train-per-time': 105.00162888828912,\n",
      " 'valid-accuracy': 23.266666631062826,\n",
      " 'valid-all-time': 7.7054752962929856,\n",
      " 'valid-loss': 3.1219845104217527,\n",
      " 'valid-per-time': 0.6421229413577488,\n",
      " 'valtest-accuracy': 22.833333323160808,\n",
      " 'valtest-all-time': 15.410950592585971,\n",
      " 'valtest-loss': 3.142311067581177,\n",
      " 'valtest-per-time': 1.2842458827154977}\n",
      "Its performance on ImageNet16-120 with 200-epoch-training\n",
      "{'test-accuracy': 41.44444444783529,\n",
      " 'test-all-time': 128.4245882715503,\n",
      " 'test-loss': 2.3114658287896046,\n",
      " 'test-per-time': 0.6421229413577515,\n",
      " 'train-accuracy': 50.604262800759415,\n",
      " 'train-all-time': 21000.325777657865,\n",
      " 'train-loss': 1.8626367051877495,\n",
      " 'train-per-time': 105.00162888828932,\n",
      " 'valid-accuracy': 40.777777659098305,\n",
      " 'valid-all-time': 128.4245882715503,\n",
      " 'valid-loss': 2.3157107713487415,\n",
      " 'valid-per-time': 0.6421229413577515,\n",
      " 'valtest-accuracy': 41.11111109754774,\n",
      " 'valtest-all-time': 256.8491765431006,\n",
      " 'valtest-loss': 2.313588462617662,\n",
      " 'valtest-per-time': 1.284245882715503}\n"
     ]
    }
   ],
   "source": [
    "# query the largest model's performance\n",
    "largest_candidate_tss = '|nor_conv_3x3~0|+|nor_conv_3x3~0|nor_conv_3x3~1|+|nor_conv_3x3~0|nor_conv_3x3~1|nor_conv_3x3~2|'\n",
    "arch_index = api.query_index_by_arch(largest_candidate_tss)\n",
    "print('The architecture-index for the largest model is {:}'.format(arch_index))\n",
    "datasets = ('cifar10', 'cifar100', 'ImageNet16-120')\n",
    "for dataset in datasets:\n",
    "    print('Its performance on {:} with 12-epoch-training'.format(dataset))\n",
    "    info = api.get_more_info(arch_index, dataset, hp='12', is_random=False)\n",
    "    pprint(info)\n",
    "    print('Its performance on {:} with 200-epoch-training'.format(dataset))\n",
    "    info = api.get_more_info(arch_index, dataset, hp='200', is_random=False)\n",
    "    pprint(info)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
